package com.offcn.test;

import java.util.concurrent.TimeUnit;

/**
 * volatail的可见性,volatail的write让各线程的缓存中的数据invalid
 */
public class VolatailTest1 {
    volatile static int i = 3;
    public static void main(String[] args) throws Exception {
        new Thread(()->{
            System.out.println("线程开启");
            while (true){
                if (i!=3){
                    break;
                }
            }
            System.out.println("线程结束");
        }).start();
        TimeUnit.SECONDS.sleep(3);
        i = 4;
    }
}
